//
//  LJM_RANK_WebView_ViewController.m
//  wind
//
//  Created by 李金明 on 16/1/19.
//  Copyright © 2016年 李金明. All rights reserved.
//

#import "LJM_RANK_WebView_ViewController.h"

@interface LJM_RANK_WebView_ViewController () <UIWebViewDelegate>
@property (nonatomic, retain) UIWebView *webV;
@property (nonatomic, retain) UIActivityIndicatorView *testActivityIndicator;
@property (nonatomic, retain) UIApplication *application;
@property (nonatomic, retain) UIButton *bactButton;
@property (nonatomic, retain) UIView *barview;
@property (nonatomic, retain) UILabel *titleLab;
@end

@implementation LJM_RANK_WebView_ViewController
- (void)dealloc
{
    self.backDelegate = nil;
    [_bactButton release];
    [_barview release];
    [_titleLab release];
    [_testActivityIndicator release];
    [_application release];
    [_url release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    //增加navigation
    [self addNavigationBar];
    self.webV = [LJMNetworkTool getWebViewWithStr:self.url];
    self.webV.delegate = self;
    self.view = self.webV;
    
    
    //菊花转
        [self addUIActivityIndicatorView];


}
#pragma 添加navigationBar
- (void)addNavigationBar
{
    self.barview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, NAVIGATIONBARHEIGHT)];
    self.barview.userInteractionEnabled = YES;
    self.barview.backgroundColor = [UIColor colorWithRed:69 / 255.0 green:175 / 255.0 blue:248 / 255.0 alpha:1.0];
    [self.navigationController.navigationBar addSubview:self.barview];
    [_barview release];
    self.bactButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.bactButton setTitle:@"返回" forState:UIControlStateNormal];
    [self.bactButton addTarget:self action:@selector(barAction) forControlEvents:UIControlEventTouchUpInside];
    [self.bactButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.barview addSubview:self.bactButton];
    [self.bactButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.barview.mas_left).offset(10);
        make.width.mas_equalTo(@50);
        make.bottom.equalTo(self.barview.mas_bottom).offset(-5);
        make.height.mas_equalTo(@30);
    }];
    self.titleLab = [[UILabel alloc] init];
    self.titleLab.text = @"网页";
    self.titleLab.textAlignment = NSTextAlignmentCenter;
    self.titleLab.font = [UIFont boldSystemFontOfSize:20];
    self.titleLab.textColor = [UIColor whiteColor];
    [self.barview addSubview:self.titleLab];
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.barview.mas_centerX);
        make.width.mas_equalTo(@50);
        make.centerY.equalTo(self.bactButton.mas_centerY);
        make.height.mas_equalTo(@30);
    }];
    
    
    
    
}
#pragma 返回按钮
- (void)barAction
{

    [self.navigationController popViewControllerAnimated:YES];
    [self.barview removeFromSuperview];
    [self.backDelegate backRANK_WebView_Delegate];
    [self.testActivityIndicator stopAnimating];
    self.application.networkActivityIndicatorVisible = NO;
    
    
}
#pragma 增加个菊花转
- (void)addUIActivityIndicatorView
{
    //    //增加个菊花转
    self.testActivityIndicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    self.testActivityIndicator.backgroundColor = [UIColor blackColor];
    self.testActivityIndicator.frame = CGRectMake(([UIScreen mainScreen].bounds.size.width - 60) / 2 , [UIScreen mainScreen].bounds.size.height / 2 - 100, 60, 60);
    self.testActivityIndicator.layer.cornerRadius = 10;
    self.testActivityIndicator.layer.masksToBounds = YES;
    [self.barview addSubview:self.testActivityIndicator];
    [_testActivityIndicator release];
    [self.testActivityIndicator startAnimating];
    //增加网络旁边菊花转的方法
    self.application = [UIApplication sharedApplication];
    self.application.networkActivityIndicatorVisible = YES;
    
}
#pragma webView的协议方法
- (void)webViewDidStartLoad:(UIWebView *)webView
{
    
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
//    if ([[[LJM_night shareDataBase] getStr] isEqualToString:@"YES"]) {
//        [self.webV stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.background='#BABABA'"];
//        
//        
//    } else {
//        [self.webV stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.background='#FFFFFF'"];
//    }
//    
    [self.testActivityIndicator stopAnimating];
    self.application.networkActivityIndicatorVisible = NO;
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(nullable NSError *)error
{
    UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"提示" message:@"" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    [alertC addAction:action];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
